// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/EventInfoApi'

import AddClass from '@api/base/model/EventInfoReq'
import BaseClass from '@api/base/model/EventInfoDto'
import MemberClass from '@api/base/model/EventMemberDto'
import SupplyClass from '@api/base/model/EventSupplyDto'
import FileClass from '@api/base/model/FileInfoDto'

const CLIENT = CORE.grpcCLIENT(Client)
const MEMBER = [MemberClass, 'eventMemberDtos', 1]
const SUPPLY = [SupplyClass, 'eventSupplyDtos', 1]
const FILE = [FileClass, 'fileInfoDtos', 'fileList']
const BASE = [BaseClass, 'dto', null, (dto, obj) => CORE.grpcDTO(dto, obj, MEMBER, SUPPLY, FILE)]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const imageList = one.imageList.map((fileUrl) => ({ fileUrl, fileName: fileUrl.split('/').pop(), fileType: 1 }))
    const fileList = [...imageList, ...one.videoList]
    const DTO = CORE.grpcDTO(AddClass, { ...one, fileList }, BASE)
    await CORE.grpc(TIP, CLIENT, 'eventInfoSave', DTO)
    return CORE.grpcOK(TIP)
  },
}
